package be.ipl.finito.util;

import java.io.Serializable;

import be.ipl.finito.domaine.Grille;
import be.ipl.finito.domaine.Jeton;

//Classe utilitaire qui facilite la gestion des cases de la grille
@SuppressWarnings("serial")
public class CaseGrille implements Serializable {

	private int index;

	private Jeton jeton;
	
	protected CaseGrille() {
	}

	public CaseGrille(Jeton jeton, int index) {
		Util.checkObject(jeton);
		Util.checkPositive(index);
		this.jeton = jeton;
		this.index = index;

	}

	public int getIndex() {
		return index;
	}

	public Jeton getJeton() {
		return jeton;
	}
	
	public Grille getGrille(){
		return null;
	}

	public boolean placerJeton(Jeton jeton) {
		Util.checkObject(jeton);
		if (this.jeton != null) {
			return false;
		}
		if (this.jeton == jeton) {
			return false;
		}
		this.jeton = jeton;
		return true;
	}

	public boolean modifierIndex(int index) {
		Util.checkPositive(index);
		if (this.index == index) {
			return false;
		}
		this.index = index;
		return true;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + index;
		result = prime * result + ((jeton == null) ? 0 : jeton.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CaseGrille other = (CaseGrille) obj;
		if (index != other.index)
			return false;
		if (jeton == null) {
			if (other.jeton != null)
				return false;
		} else if (!jeton.equals(other.jeton))
			return false;
		return true;
	}

}
